<?php

        require_once "../../konfigurasi.php";
        
        koneksi_buka();
        
         $array['1'] =  'senin'; 
		 $array['2'] =  'selasa'; 
		 $array['3'] =  'rabu'; 
		 $array['4'] =  'kamis'; 
		 $array['5'] =  'jumat'; 
		 $array['6'] =  'sabtu'; 
		 $array['7'] =  'minggu'; 
        
        if(isset($_GET['row_id'])){
                $row_id = $_GET['row_id'];
        }
        
        if(isset($_POST['row_id'])){
                $row_id = $_POST['row_id'];
        }
        
        if(isset($_POST['column'])){
                $column = $_POST['column'];
        }
        
         if(isset($_POST['value'])){
                $value = $_POST['value'];
        }
        
        if(isset($_POST['siswa'])){
                $siswa = $_POST['siswa'];
        }
        
         if(isset($_POST['materi'])){
                $materi = $_POST['materi'];
        }
                  
        $tgl_daftar = date("Y-m-d");
        $wkt = date("H:i:s");
		if($column=="5"){
			$column_name = "hari";
		}else if($column=="6"){
			$column_name = "jam_mulai";
		}else{
			$column_name = "jam_selesai";
		}
		
			//echo $column_name ." ".$value;
		if($row_id=="-"){
			
			$q = "INSERT INTO jadwal_praktikum
					($column_name, siswa, materi) 
					VALUES('$value', '$siswa', '$materi')";
			$result = mysql_query($q);
			if($result){
				$id = mysql_insert_id();
					
				if($column_name=="hari"){
					echo $id.",".$array[$value];				
				}else{
					echo $id.",".$value;
				}
				
			}else{
				echo 'failed query :'.$q ;
			}	
		}else{
			$result = mysql_query("UPDATE jadwal_praktikum SET 
					$column_name = '$value'
					WHERE id=".$row_id);
					
			if($result){
				if($column_name=="hari"){
					echo $array[$value]." saved";
				}else{
					echo $value." saved";
				}
			}else{
					echo 'failed';
			}
		
		}
        
		
		
?>
